#!/bin/sh
echo "Content-type: text/html\n"

# read in our parameters
DRINK=`echo "$QUERY_STRING" | sed -n 's/^.*drink=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`

PID=`pidof santabarbot`

# our html code
cat header.html

# test if any parameters were passed
if [ $DRINK ]
then
  # If the serial interface is running 
  if [ $PID ]
  then
    echo "<div class='menu'>"
    echo "<a href='barbot.cgi'>Santa BarBot is already making a drink...<br>"
    echo "</a></div>"
  else
    echo "<div class='menu'>"
    echo "<a href='barbot.cgi'>Santa BarBot is making a $DRINK !<br>"
    MAXOUT=`/home/filitchp/santa-barbot/server/max -q $DRINK &`
    #espeak "stuff"
    STUFF=`./santabarbot $DRINK`
    #echo $STUFF
    #echo $MAXOUT
    echo "<br>"
    #echo $?
    echo "Click here to go back to the main menu";
    echo "<br>"
    echo "</a></div>"
  fi
else
  #
  cat menu.html
  cat debugMenu.html
fi

cat footer.html

